package com.zs.controller;

import com.zs.pojo.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("user")
    public List<User> queryUseByPage(@RequestParam(defaultValue = "1") int page,
                                     @RequestParam(defaultValue = "10") int size) {

        System.out.println("page:"+page+" size:"+size);
        User user = new User();
        user.setAge(18);
        user.setUsername("zs");
        user.setId(1);
        List<User> userList = new ArrayList<>();
        userList.add(user);
        return userList;
    }

    @PostMapping("user")
    public User addUser(@RequestBody User user) {
        System.out.println(user);
        return user;
    }

    @GetMapping("{id}")
    public User queryUserById(@PathVariable(name = "id") int id){
        User user = new User();
        user.setId(id);
        user.setUsername("zs");
        user.setAge(18);
        return user;
    }

    @PutMapping("{id}")
    public User updateUser(@PathVariable(name = "id")int id, @RequestBody User user){
        System.out.println("id=" + id + " user=" +user);
        return user;
    }
    @DeleteMapping("{id}")
    public String deleteUser(@PathVariable(name = "id") int id){
        System.out.println("id=" + id);
        return "success";
    }
    @GetMapping("search")
    public List<User> queryUserByCOnfiguration(String keyword, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int size){
        User user = new User();
        user.setId(1);
        user.setUsername("zs");
        user.setAge(18);
        List<User> userList = new ArrayList<>();
        userList.add(user);
        return userList;
    }



}
